package com.sudoku.listener;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.sudoku.common.Constants;
import com.sudoku.common.SqliteUtils;
import com.sudoku.ui.Sudoku;
import com.sudoku.ui.content.SMenu;

public class MenuNewGameListener implements ActionListener {

	private Sudoku sudoku;
	
	public MenuNewGameListener(Sudoku sudoku) {
		this.sudoku= sudoku;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		/**
		 * 检测当前在哪个界面，如果是在数独界面，则需要保存当前进度
		 */
		SqliteUtils.insert(sudoku);
		
		/**
		 * 读取存档
		 * 1. tfCells 玩家填写情况
		 * 2. puzzle 答案
		 * 3. mask 遮盖情况
		 * 4. level 难度等级
		 */
		CardLayout cardLayout = (CardLayout)(sudoku.getCards().getLayout());
		cardLayout.show(sudoku.getCards(), Constants.LABEL_HOME);
		sudoku.setAtCard(Constants.LABEL_HOME);
		sudoku.setMenu(new SMenu(sudoku));
	}

}
